// qGameVideo.cpp (修改后的部分)
#include "qGameVideo.h"
#include "gobangwidget.h"
#include "MistakeBook.h"
#include "VideoWidget.h"  // 添加这行
#include "music_player.h"
#include "LoginDialog.h"
#include "ChatWidget.h"
#include "Mapper.h"
#include "pokemonbattle.h"
#include "tomatoclockwidget.h"

qGameVideo::qGameVideo(QWidget* parent)
    : QMainWindow(parent)
{
    initUi();

    setUiStyle();
    connectSignalToSolts();
}

void qGameVideo::setUiStyle()
{
    m_btnGoBang->setObjectName("btnGoBang");
    //m_btnVideo->setObjectName("btnVideo");
    m_btnSchedule->setObjectName("btnSchedule");
    m_ErrorNode->setObjectName("btnErrorNode");
    m_MusicHall->setObjectName("btnMusicHall");
    m_ChatRoom->setObjectName("btnChatRoom");
    m_btnLogin->setObjectName("btnLogin");
    // 设置stacked widget的objectName
    sgt->setObjectName("stackedWidget");

}

void qGameVideo::initUi()
{
    // 创建按钮
    m_btnGoBang = new QPushButton("五子棋");
    //m_btnVideo = new QPushButton("阅览室");
    m_btnSchedule = new QPushButton("作息表");
    m_ErrorNode = new QPushButton("错题本");
    m_MusicHall = new QPushButton("音乐厅");
    m_ChatRoom = new QPushButton("聊天室");
    m_btnLogin = new QPushButton("身份信息保存");
    m_btnMaper=new QPushButton("地图生成和解析");
    m_btnPokemon=new QPushButton("宝可梦");
    m_btnTomato=new QPushButton("番茄钟");


    // 创建堆叠窗口
    sgt = new QStackedWidget(this);

    // 初始化各个页面
    wgt_goBnag = new GobangWidget();
    wgt_schedule = new DailySchedule();
    wgt_error = new MistakeBook();
    //wgt_video = new VideoWidget();  // 使用新的VideoWidget
    wgt_music = new MusicPlayerWidget();
    wgt_chat = new ChatWidget();
    wgt_login = new LoginDialog();
    wgt_maper = new Mapper();
    wgt_pokemon =new PokemonBattle();
    wgt_tomato = new TomatoClockWidget();

    // 添加到堆叠窗口
    //sgt->addWidget(wgt_video);
    sgt->addWidget(wgt_goBnag);
    sgt->addWidget(wgt_schedule);
    sgt->addWidget(wgt_error);
    sgt->addWidget(wgt_music);
    sgt->addWidget(wgt_chat);
    sgt->addWidget(wgt_login);
    sgt->addWidget(wgt_maper);
    sgt->addWidget(wgt_pokemon);
    sgt->addWidget(wgt_tomato);
    // 创建主布局
    QVBoxLayout* vboxMain = new QVBoxLayout();
    QHBoxLayout* hboxPlayModel = new QHBoxLayout();

    //hboxPlayModel->addWidget(m_btnVideo);
    /*hboxPlayModel->addWidget(m_btnGoBang);
    hboxPlayModel->addWidget(m_btnSchedule);
    hboxPlayModel->addWidget(m_ErrorNode);
    hboxPlayModel->addWidget(m_MusicHall);
    hboxPlayModel->addWidget(m_ChatRoom);
    hboxPlayModel->addWidget(m_btnLogin);
    hboxPlayModel->addWidget(m_btnMaper);
    hboxPlayModel->addWidget(m_btnPokemon);*/
    hboxPlayModel->addWidget(m_btnTomato);


    vboxMain->addLayout(hboxPlayModel);
    vboxMain->addWidget(sgt);

    QWidget* wgtMain = new QWidget(this);
    wgtMain->setLayout(vboxMain);
    setCentralWidget(wgtMain);

    sgt->setCurrentIndex(8);  // 默认显示阅览室
}

void qGameVideo::connectSignalToSolts()
{
    // 连接按钮信号
    connect(m_btnVideo, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(0);
        });
    connect(m_btnGoBang, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(1);
        });
    connect(m_btnSchedule, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(2);
        });
    connect(m_ErrorNode, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(3);
        });
    connect(m_MusicHall, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(4);
        });
    connect(m_ChatRoom, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(5);
        });
    connect(m_btnLogin, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(6);
        });
    connect(m_btnMaper, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(7);
        });
    connect(m_btnPokemon, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(8);
        });
    connect(m_btnTomato, &QPushButton::clicked, [this]() {
        sgt->setCurrentIndex(9);
        });
}


qGameVideo::~qGameVideo()
{
    // 清理资源
    qDebug() << "主窗口资源释放完成";
}